import json

import allure
import pytest
from Cs import Cr
from Hdjg import Hdjg
class Test_Dxm:#1，http,code 对测试通过  2http不对直接pass  3http 对 code 不对 测试不通过
    # @allure.title("登录接口")
    # @pytest.mark.parametrize('cr,lxcode',Cr().dl())
    # def test_Dl(self,cr,lxcode):
    #     rp=Hdjg().Dl(cr)#返回了一个最终的cookie，只需在分别去读取http，code
    #     if rp.status_code !=200:
    #         print(f'请求错误，状态码为{rp.status_code}')
    #         assert False,'测试不通过'
    #     elif rp.status_code == 200:
    #         assert json.loads(rp.text)['code']==lxcode,'测试通过'
    #     else:
    #         assert False,'测试不通过'

    # @allure.title("注册接口")
    # @pytest.mark.parametrize('username,yhm,password,mm,lxcode,dc,z', Cr().zc())
    # def test_Zc(self, username,yhm,password,mm,lxcode,dc,z):
    #     zx = Hdjg().Zc(username,yhm,password,mm,dc,z)
    #     if zx.status_code != 200:
    #         print(f'请求错误，状态码为{zx.status_code}')
    #         assert False, '测试不通过'
    #     elif zx.status_code == 200:
    #         assert json.loads(zx.text)['code'] == lxcode, '测试通过'
    #     else:
    #         assert False, '测试不通过'

    # @allure.title('修改个人信息')
    # @pytest.mark.parametrize('dl,id,cr,lxcode',Cr().xggrxx())
    # def test_Xggrxx(self,dl,id,cr,lxcode):
    #     Hdjg().Dl(dl)
    #     zx=Hdjg().Xggrxx(id,cr)
    #     if zx.status_code != 200:
    #         assert False,f'测试不通过，请求错误，http为{zx.status_code}'
    #     elif zx.status_code ==200:
    #         assert json.loads(zx.text)['code']==lxcode,'测试通过'
    #     else:
    #         assert False,'测试不通过'

    # @allure.title('改密码')
    # @pytest.mark.parametrize('dl,cr,lxcode',Cr().gmm())
    # def test_Gmm(self,dl,cr,lxcode):
    #     Hdjg().Dl(dl)
    #     zx=Hdjg().Gmm(cr)
    #     if zx.status_code !=200:
    #         assert False,f'测试不通过，http状态码为{zx.status_code}'
    #     elif zx.status_code==200:
    #         assert json.loads(zx.text)['code']==lxcode,'测试通过'
    #     else:
    #         assert False,'测试不通过'

    # @allure.title('默认银行卡')
    # @pytest.mark.parametrize('dl,id,lxcode',Cr().mryhk())
    # def test_Mryhk(self,dl,id,lxcode):
    #     Hdjg().Dl(dl)
    #     zx=Hdjg().Mryhk(id)
    #     if zx.status_code !=200:
    #         assert False,f'测试不通过，http码为{zx.status_code}'
    #     elif zx.status_code==200:
    #         assert json.loads(zx.text)['code']==lxcode,'测试通过'
    #     else:
    #         assert False,'测试不通过'

    # @allure.title('添加银行卡')
    # @pytest.mark.parametrize('dl,cr,lxcode',Cr().tjyhk())
    # def test_Tjyhk(self,dl,cr,lxcode):
    #     Hdjg().Dl(dl)
    #     zx=Hdjg().Tjyhk(cr)
    #     if zx.status_code != 200:
    #         assert False,'测试不通过，http状态不对'
    #     elif zx.status_code==200:
    #         assert json.loads(zx.text)['code']==lxcode,'测试通过'
    #     else:
    #         assert False,'测试不通过'

    # @allure.title('借贷')
    # @pytest.mark.parametrize('dl,cr,lxcode',Cr().wd())
    # def test_Wd(self,dl,cr,lxcode):
    #     Hdjg().Dl(dl)
    #     zx=Hdjg().Wd(cr)
    #     if zx.status_code != 200:
    #         assert False,'测试不通过，http码不对'
    #     elif zx.status_code == 200:
    #         assert json.loads(zx.text)['code']==lxcode,'测试通过'
    #     else:
    #         assert False,'测试不通过'

    @allure.title('基金理财')
    @pytest.mark.parametrize('dl,cr,lxcode',Cr().jjlc())
    def test_jjlc(self,dl,cr,lxcode):
        Hdjg().Dl(dl)
        zx=Hdjg().Jjlc(cr)
        if zx.status_code != 200:
            assert False,'测试不通过，http状态码不对'
        elif zx.status_code == 200:
            assert json.loads(zx.text)['code']==lxcode,'测试通过'
        else:
            assert False,'测试不通过'

    @allure.title('期限理财')
    @pytest.mark.parametrize('dl,cr,lxcode', Cr().qxlc())
    def test_qxlc(self, dl, cr, lxcode):
        Hdjg().Dl(dl)
        zx = Hdjg().Qxlc(cr)
        if zx.status_code != 200:
            assert False, '测试不通过，http状态码不对'
        elif zx.status_code == 200:
            assert json.loads(zx.text)['code'] == lxcode, '测试通过'
        else:
            assert False, '测试不通过'

    @allure.title('零钱理财')
    @pytest.mark.parametrize('dl,cr,lxcode', Cr().lqlc())
    def test_lqlc(self, dl, cr, lxcode):
        Hdjg().Dl(dl)
        zx = Hdjg().Lqlc(cr)
        if zx.status_code != 200:
            assert False, '测试不通过，http状态码不对'
        elif zx.status_code == 200:
            assert json.loads(zx.text)['code'] == lxcode, '测试通过'
        else:
            assert False, '测试不通过'